package com.lyn.auxiliarytool.views.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewbinding.ViewBinding;
import com.lyn.auxiliarytool.R;

/**
 * Activity 基类
 * @author longyn 2022/11/29
 * @version 1.0.0
 */
public abstract class BaseActivity<V extends ViewBinding> extends AppCompatActivity {

    public V vb;
    public Context context;
    private ProgressDialog progressDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        create(savedInstanceState);
        this.context = this;
        vb = getViewBinding();
        setContentView(vb.getRoot());
        initView();
    }
    public abstract void create(@Nullable Bundle savedInstanceState);

    public abstract V getViewBinding();

    public abstract void initView();


    public void showLoading(){
        if (progressDialog!=null){
            if (progressDialog.isShowing()){
                progressDialog.dismiss();
            }
            progressDialog = null;
        }
        progressDialog = new ProgressDialog(context);
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.setTitle(getString(R.string.hint));
        progressDialog.setMessage(getString(R.string.pleaseLater));
        progressDialog.show();
    }

    public void hideLoading(){
        if (progressDialog!=null){
            if (progressDialog.isShowing()){
                progressDialog.dismiss();
            }
            progressDialog = null;
        }
    }

    public void toast(String message){
        Toast.makeText(context,message,Toast.LENGTH_LONG).show();
    }

}
